interface { "KHChatRoomRequsetManager" }

function requestPreChatRoom_completion(self, enterModel, completion)
    print("yamhot 222 33333!!!")
    if enterModel:enterRoomNo() == nil then
        return
    end

    enterModel:setEnterTimeStr(AppDateTool:getNowTimeTimestamp())

    local params = {}
    params["roomNo"] = enterModel:enterRoomNo()
    params["password"] = enterModel:password()
    params["timestamp"] = enterModel:enterTimeStr()
    params["isFromEditRoom"] = enterModel:isFromEditRoom()
    print("yamhot params")
    print(params)

    LCNetworkManager:post_parameters_completionHandler("/api/v1/voice-room/enter-base", params,
        toblock(
            function(succeed, response)
                print("yamhot block!!")
                if KHChatRoomsManager:sharedManager():roomCtrl() == nil then
                    if completion then
                        completion(false, nil)
                    end
                    return
                end

                -- 模拟异常场景
                local res = {data=NSNull:null()}

                if succeed then
                    if KHPackageManager:checkResponseSucceed(res) then
                        if completion then
                            completion(true, response)
                        end
                    else
                        if completion then
                            -- completion(false, res)
                            if res == NSNull:null() then
                                print("yamhot null! 11111")                                
                                completion(false, nil)
                            elseif res["data"] == NSNull:null() then
                                print("yamhot null! 2222")
                                completion(false, nil)
                            else
                            print("yamhot null! 3333")
                                completion(false, res)
                            end
                        end
                    end
                else
                    if completion then
                        completion(false, nil)
                    end
                end
            end, { "void", "BOOL", "id" }
        ))
end
